@{
    ViewData["Title"] = "库存现有量";
    Layout = null;
}
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>库存现有量管理</title>
    <script src="~/libs/scripts/jquery-3.4.1.min.js"></script>
    <link href="~/libs/scripts/layui-v2.5.6/layui/css/layui.css" rel="stylesheet" />
    <script src="~/libs/scripts/layui-v2.5.6/layui/layui.js"></script>
    <style>
        /* 页面整体布局 */
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        html, body {
            height: 100vh;
            overflow: hidden; /* 取消页面滚动条 */
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            font-family: 'Microsoft YaHei', sans-serif;
        }

        /* 主容器 - 固定页面大小 */
        .main-container {
            display: flex;
            height: 100vh;
            width: 100vw;
            gap: 4px;
            padding: 4px;
            box-sizing: border-box;
            overflow: hidden;
            background: #f5f7fa;
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
        }

        /* 左侧物料分类树 - 固定宽高 */
        .left-panel {
            width: 240px;
            min-width: 240px;
            max-width: 240px;
            height: calc(100vh - 8px);
            background: white;
            border-radius: 8px;
            box-shadow: 0 1px 2px 0 rgba(0,0,0,.03), 0 1px 6px -1px rgba(0,0,0,.02), 0 2px 4px 0 rgba(0,0,0,.02);
            display: flex;
            flex-direction: column;
            overflow: hidden;
            transition: transform 0.2s ease;
        }

        .left-panel:hover {
            transform: translateY(-1px);
        }

        .left-panel-header {
            padding: 16px;
            background: #f8fafd;
            border-bottom: 1px solid rgba(0,0,0,.06);
            color: #1677ff;
            font-weight: 500;
        }

        .left-panel-header h3 {
            margin: 0;
            font-size: 15px;
            display: flex;
            align-items: center;
            gap: 8px;
        }

        .tree-container {
            flex: 1;
            overflow: auto;
            padding: 12px;
        }

        /* 右侧内容区域 */
        .right-panel {
            flex: 1;
            height: calc(100vh - 8px);
            background: white;
            border-radius: 8px;
            box-shadow: 0 1px 2px 0 rgba(0,0,0,.03), 0 1px 6px -1px rgba(0,0,0,.02), 0 2px 4px 0 rgba(0,0,0,.02);
            display: flex;
            flex-direction: column;
            overflow: hidden;
        }

        /* 搜索区域 */
        .search-container {
            padding: 12px 16px;
            background: #f8fafd;
            border-bottom: 1px solid rgba(0,0,0,.06);
        }

        .search-form {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
            gap: 12px 16px;
            align-items: end;
        }

        .search-item {
            display: flex;
            flex-direction: column;
            gap: 4px;
        }

        .search-item label {
            font-size: 13px;
            color: #666;
            font-weight: 500;
        }

        .search-item input,
        .search-item select {
            height: 32px;
            padding: 0 12px;
            border: 1px solid #e5e7eb;
            border-radius: 6px;
            font-size: 13px;
            transition: all 0.2s;
            background: white;
        }

        .search-item input:hover,
        .search-item select:hover {
            border-color: #1677ff;
        }

        .search-item input:focus,
        .search-item select:focus {
            border-color: #1677ff;
            box-shadow: 0 0 0 2px rgba(22,119,255,.1);
            outline: none;
        }

        /* 按钮样式 */
        .action-buttons {
            display: flex;
            gap: 8px;
        }

        .btn-search {
            height: 32px;
            padding: 0 16px;
            background: #1677ff;
            border: none;
            border-radius: 6px;
            color: white;
            font-size: 13px;
            cursor: pointer;
            transition: all 0.2s;
            display: flex;
            align-items: center;
            gap: 4px;
        }

        .btn-search:hover {
            background: #4096ff;
        }

        .btn-reset {
            height: 32px;
            padding: 0 16px;
            background: white;
            border: 1px solid #e5e7eb;
            border-radius: 6px;
            color: #666;
            font-size: 13px;
            cursor: pointer;
            transition: all 0.2s;
            display: flex;
            align-items: center;
            gap: 4px;
        }

        .btn-reset:hover {
            border-color: #1677ff;
            color: #1677ff;
        }

        .btn-export {
            height: 32px;
            padding: 0 16px;
            background: #52c41a;
            border: none;
            border-radius: 6px;
            color: white;
            font-size: 13px;
            cursor: pointer;
            transition: all 0.2s;
            display: flex;
            align-items: center;
            gap: 4px;
        }

        .btn-export:hover {
            background: #73d13d;
        }

        .btn-refresh {
            height: 32px;
            padding: 0 16px;
            background: #722ed1;
            border: none;
            border-radius: 6px;
            color: white;
            font-size: 13px;
            cursor: pointer;
            transition: all 0.2s;
            display: flex;
            align-items: center;
            gap: 4px;
        }

        .btn-refresh:hover {
            background: #9254de;
        }

        /* 表格区域 */
        .table-container {
            flex: 1;
            display: flex;
            flex-direction: column;
            min-height: 0;
            padding: 16px;
            padding-bottom: 0;
        }

        .table-header {
            padding-bottom: 12px;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        .table-title {
            font-size: 15px;
            font-weight: 500;
            color: #1f2937;
            display: flex;
            align-items: center;
            gap: 8px;
        }

        .table-stats {
            display: flex;
            gap: 16px;
            font-size: 13px;
            color: #666;
        }

        .stat-item {
            display: flex;
            align-items: center;
            gap: 4px;
        }

        .stat-item .count {
            color: #1677ff;
            font-weight: 500;
        }

        .table-wrapper {
            flex: 1;
            min-height: 0;
            display: flex;
            flex-direction: column;
            border: 1px solid #f0f0f0;
            border-radius: 8px;
            overflow: hidden;
        }

        /* 表格样式优化 */
        .layui-table {
            margin: 0 !important;
        }

        .layui-table thead tr {
            background: #fafafa !important;
        }

        .layui-table th {
            font-size: 13px !important;
            font-weight: 500 !important;
            color: #1f2937 !important;
            background: #fafafa !important;
            border-bottom: 1px solid #f0f0f0 !important;
            padding: 12px 8px !important;
        }

        .layui-table td {
            padding: 12px 8px !important;
            font-size: 13px !important;
        }

        .layui-table-cell {
            height: 20px !important;
            line-height: 20px !important;
        }

        .layui-table-hover {
            background-color: #f8fafd !important;
        }

        /* 状态标签样式 */
        .status-valid {
            display: inline-flex;
            align-items: center;
            gap: 4px;
            padding: 2px 8px;
            background: #f6ffed;
            border: 1px solid #b7eb8f;
            border-radius: 4px;
            color: #52c41a;
            font-size: 12px;
        }

        .status-invalid {
            display: inline-flex;
            align-items: center;
            gap: 4px;
            padding: 2px 8px;
            background: #fff2f0;
            border: 1px solid #ffccc7;
            border-radius: 4px;
            color: #ff4d4f;
            font-size: 12px;
        }

        /* 分页样式优化 */
        .layui-laypage {
            margin: 0;
            padding: 12px;
            text-align: right;
            background: #fff;
            border-top: 1px solid #f0f0f0;
        }

        .layui-laypage a,
        .layui-laypage span {
            margin: 0 4px;
            padding: 0 12px;
            height: 32px;
            line-height: 30px;
            border-radius: 6px;
            font-size: 13px;
        }

        .layui-laypage .layui-laypage-curr .layui-laypage-em {
            background-color: #1677ff !important;
            border-radius: 6px;
        }

        /* 数量样式 */
        .quantity-cell {
            font-weight: 500;
        }

        .quantity-low {
            color: #ff4d4f;
        }

        .quantity-normal {
            color: #52c41a;
        }

        .quantity-high {
            color: #1677ff;
        }

        /* 详情按钮样式 */
        .layui-btn-xs {
            height: 24px !important;
            line-height: 24px !important;
            padding: 0 8px !important;
            font-size: 12px !important;
            border-radius: 4px !important;
        }

        .layui-btn-normal {
            background-color: #1677ff !important;
        }

        .layui-btn-normal:hover {
            background-color: #4096ff !important;
        }

        /* 树形组件样式 */
        .layui-tree {
            background: transparent;
        }

        .layui-tree-node {
            padding: 4px 0;
        }

        .layui-tree-txt {
            font-size: 14px;
            padding: 10px 16px;
            border-radius: 8px;
            transition: all 0.3s ease;
            margin: 2px 0;
            white-space: nowrap; /* 防止文字换行 */
        }

        .layui-tree-txt:hover {
            background: linear-gradient(135deg, #e6f7ff 0%, #d6f0ff 100%);
            color: #1890ff;
            transform: translateX(4px);
        }

        .layui-tree-node-selected .layui-tree-txt {
            background: linear-gradient(135deg, #1890ff 0%, #096dd9 100%) !important;
            color: white !important;
            box-shadow: 0 4px 12px rgba(24, 144, 255, 0.3);
        }

        /* 响应式适配 */
        @@media (max-width: 1400px) {
            .left-panel {
                width: 280px;
                min-width: 280px;
                max-width: 280px;
            }
            .search-form {
                grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
            }
        }

        @@media (max-width: 1200px) {
            .left-panel {
                width: 260px;
                min-width: 260px;
                max-width: 260px;
            }
        }

        @@media (max-width: 768px) {
            .main-container {
                flex-direction: column;
                height: 100vh;
                padding: 8px;
            }

            .left-panel {
                width: 100%;
                min-width: auto;
                max-width: none;
                height: 200px;
                flex-shrink: 0;
            }

            .right-panel {
                flex: 1;
                height: calc(100vh - 220px);
            }

            .search-form {
                grid-template-columns: 1fr;
            }

            .action-buttons {
                flex-wrap: wrap;
            }
        }

        /* 加载状态 */
        .loading-overlay {
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: rgba(255, 255, 255, 0.8);
            display: flex;
            align-items: center;
            justify-content: center;
            z-index: 1000;
            border-radius: 8px;
        }

        .loading-spinner {
            width: 40px;
            height: 40px;
            border: 4px solid #f3f3f3;
            border-top: 4px solid #1890ff;
            border-radius: 50%;
            animation: spin 1s linear infinite;
        }

        @@keyframes spin {
            0% { transform: rotate(0deg); }
            100% { transform: rotate(360deg); }
        }
    </style>
</head>
<body>
    <div class="main-container">
        <!-- 左侧物料分类树 -->
        <div class="left-panel">
            <div class="left-panel-header">
                <h3><i class="layui-icon layui-icon-tree"></i> 物料产品分类</h3>
            </div>
            <div class="tree-container">
                <div id="materialTypeTree"></div>
            </div>
        </div>

        <!-- 右侧内容区域 -->
        <div class="right-panel">
            <!-- 搜索区域 -->
            <div class="search-container">
                @* <div class="search-title">
                    <i class="layui-icon layui-icon-search"></i>
                    库存查询条件
                </div> *@
                <div class="search-form" lay-filter="searchForm">
                    <div class="search-item">
                        <label>产品物料编号</label>
                        <input type="text" id="productMaterielCode" placeholder="请输入产品物料编号">
                    </div>
                    <div class="search-item">
                        <label>产品物料名称</label>
                        <input type="text" id="productMaterielName" placeholder="请输入产品物料名称">
                    </div>
                    <div class="search-item">
                        <label>仓库名称</label>
                        <input type="text" id="warehouseName" placeholder="请输入仓库名称">
                    </div>
                    <div class="search-item">
                        <label>供应商名称</label>
                        <input type="text" id="supplierName" placeholder="请输入供应商名称">
                    </div>
                    <div class="search-item">
                        <label>库存有效性</label>
                        <select id="inventoryValidity">
                            <option value="">全部</option>
                            <option value="true">有效</option>
                            <option value="false">无效</option>
                        </select>
                    </div>
                    <div class="search-items">
                        <div class="action-buttons">
                            <button type="button" class="btn-search" onclick="searchData()">
                                <i class="layui-icon layui-icon-search"></i> 搜索
                            </button>
                            <button type="button" class="btn-reset" onclick="resetSearch()">
                                <i class="layui-icon layui-icon-refresh"></i> 重置
                            </button>
                            <button type="button" class="btn-export" onclick="exportData()">
                                <i class="layui-icon layui-icon-export"></i> 导出
                            </button>
                            <button type="button" class="btn-refresh" onclick="refreshData()">
                                <i class="layui-icon layui-icon-refresh-1"></i> 刷新
                            </button>
                        </div>
                    </div>
                </div>
            </div>

            <!-- 表格区域 -->
            <div class="table-container">
                <div class="table-header">
                    <div class="table-title">
                        <i class="layui-icon layui-icon-table"></i>
                        库存现有量列表
                    </div>
                    <div class="table-stats">
                        <div class="stat-item">
                            <span>总计：</span>
                            <span class="count" id="totalCount">-</span>
                        </div>
                        <div class="stat-item">
                            <span>有效：</span>
                            <span class="count" id="validCount">-</span>
                        </div>
                        <div class="stat-item">
                            <span>无效：</span>
                            <span class="count" id="invalidCount">-</span>
                        </div>
                    </div>
                </div>
                <div class="table-wrapper">
                    <table id="inventoryTable" lay-filter="inventoryTable"></table>
                </div>
            </div>
        </div>
    </div>

    <!-- 状态模板 -->
    <script type="text/html" id="validityTpl">
        {{# if (d.inventoryValidity) { }}
            <span class="status-valid">有效</span>
        {{# } else { }}
            <span class="status-invalid">无效</span>
        {{# } }}
    </script>

    <!-- 操作按钮模板 -->
    <script type="text/html" id="operationTpl">
        <button class="layui-btn layui-btn-xs layui-btn-normal" onclick="viewDetail({{d.id}})">
            <i class="layui-icon layui-icon-about"></i> 详情
        </button>
    </script>

    <!-- 数量样式模板 -->
    <script type="text/html" id="quantityTpl">
        {{# if (d.quantityInStock <= 10) { }}
            <span class="quantity-cell quantity-low">{{d.quantityInStock}}</span>
        {{# } else if (d.quantityInStock <= 100) { }}
            <span class="quantity-cell quantity-normal">{{d.quantityInStock}}</span>
        {{# } else { }}
            <span class="quantity-cell quantity-high">{{d.quantityInStock}}</span>
        {{# } }}
    </script>

    <script>
        layui.use(['table', 'tree', 'layer', 'util', 'form'], function () {
            var table = layui.table;
            var tree = layui.tree;
            var layer = layui.layer;
            var util = layui.util;
            var form = layui.form;

            var currentMaterialTypeId = null; // 当前选中的物料分类ID
            var tableIns; // 表格实例
            var totalDataCount = 0; // 总数据量
            var validDataCount = 0; // 有效数据量
            var invalidDataCount = 0; // 无效数据量

            // 初始化页面
            init();

            function init() {
                initMaterialTypeTree();
                initTable();
                showWelcomeMessage();
            }

            // 显示欢迎信息
            function showWelcomeMessage() {
                layer.msg('欢迎使用库存现有量管理系统！', { icon: 1, time: 2000 });
            }

            // 初始化物料分类树
            function initMaterialTypeTree() {
                $.ajax({
                    url: '/WarehouseManagement/InventoryModel/GetMaterialTypeTree',
                    method: 'GET',
                    success: function (res) {
                        if (res.code === 0 && res.data) {
                            // 添加全部选项
                            var treeData = [{
                                id: 0,
                                title: '全部分类',
                                spread: true,
                                children: res.data.map(function (item) {
                                    return convertToTreeNode(item);
                                })
                            }];

                            tree.render({
                                elem: '#materialTypeTree',
                                data: treeData,
                                showCheckbox: false,
                                id: 'materialTypeTreeId',
                                isJump: false,
                                click: function (obj) {
                                    // 设置选中的分类ID
                                    currentMaterialTypeId = obj.data.id === 0 ? null : obj.data.id;
                                    // 重新加载表格数据
                                    reloadTable();
                                    // 显示选中信息
                                    layer.msg('已选择分类：' + obj.data.title, { icon: 1, time: 1500 });
                                }
                            });
                        } else {
                            layer.msg('获取物料分类失败：' + (res.msg || '未知错误'), { icon: 2 });
                        }
                    },
                    error: function () {
                        layer.msg('获取物料分类失败，请检查网络连接', { icon: 2 });
                    }
                });
            }

            // 转换数据格式为树组件需要的格式
            function convertToTreeNode(item) {
                var node = {
                    id: item.id || item.value,
                    title: item.label,
                    children: []
                };

                if (item.children && item.children.length > 0) {
                    node.children = item.children.map(function (child) {
                        return convertToTreeNode(child);
                    });
                    node.spread = false; // 默认折叠子节点
                }

                return node;
            }

            // 初始化表格
            function initTable() {
                tableIns = table.render({
                    elem: '#inventoryTable',
                    url: '/WarehouseManagement/InventoryModel/GetList',
                    page: true,
                    limit: 10,
                    limits: [10, 20, 50, 100],
                    loading: true,
                    height: 'full-230',
                    size: 'sm',
                    cellMinWidth: 60,
                    even: true,
                    cols: [[
                        { type: 'numbers', title: '序号', width: 50, align: 'center', fixed: 'left' },
                        { field: 'productMaterielCode', title: '产品物料编号', width: 120, align: 'center' },
                        { field: 'productMaterielName', title: '产品物料名称', width: 120, align: 'center' },
                        { field: 'specifications', title: '规格型号', width: 100, align: 'center' },
                        { field: 'quantityInStock', title: '在库数量', width: 80, sort: true, align: 'center', templet: '#quantityTpl' },
                        { field: 'unit', title: '单位', width: 60, align: 'center' },
                        { field: 'inboundBatchNumber', title: '入库批次号', width: 120, align: 'center' },
                        { field: 'warehouseName', title: '仓库', width: 80, align: 'center' },
                        { field: 'warehouseArea', title: '库区', width: 80, align: 'center' },
                        { field: 'warehouseLocation', title: '库位', width: 80, align: 'center' },
                        { field: 'supplierCode', title: '供应商编号', width: 100, align: 'center' },
                        { field: 'supplierName', title: '供应商名称', width: 120, align: 'center' },
                        { field: 'supplierAbbreviation', title: '供应商简称', width: 100, align: 'center' },
                        { field: 'productionWorkOrder', title: '生产工单', width: 100, align: 'center' },
                        { 
                            field: 'inboundDate', 
                            title: '入库日期', 
                            width: 100, 
                            align: 'center',
                            templet: function (d) {
                                return d.inboundDate ? util.toDateString(d.inboundDate, 'yyyy-MM-dd') : '-';
                            }
                        },
                        { field: 'inventoryValidity', title: '库存有效性', width: 90, align: 'center', templet: '#validityTpl' },
                        { title: '操作', width: 80, align: 'center', templet: '#operationTpl', fixed: 'right' }
                    ]],
                    request: {
                        pageName: 'page',
                        limitName: 'limit'
                    },
                    where: getSearchParams(),
                    done: function (res, curr, count) {
                        console.log('表格数据加载完成', res);
                        updateTableStats(res.data, count);
                    },
                    error: function (res, msg) {
                        console.error('表格数据加载失败', res, msg);
                        layer.msg('数据加载失败：' + msg, { icon: 2 });
                    }
                });
            }

            // 更新表格统计信息
            function updateTableStats(data, totalCount) {
                if (!data || !Array.isArray(data)) {
                    $('#totalCount').text('0');
                    $('#validCount').text('0');
                    $('#invalidCount').text('0');
                    return;
                }

                var validCount = data.filter(function(item) {
                    return item.inventoryValidity === true;
                }).length;

                var invalidCount = data.filter(function(item) {
                    return item.inventoryValidity === false;
                }).length;

                $('#totalCount').text(totalCount || 0);
                $('#validCount').text(validCount);
                $('#invalidCount').text(invalidCount);
            }

            // 获取搜索参数
            function getSearchParams() {
                var params = {
                    productMaterielCode: $('#productMaterielCode').val().trim(),
                    productMaterielName: $('#productMaterielName').val().trim(),
                    warehouseName: $('#warehouseName').val().trim(),
                    supplierName: $('#supplierName').val().trim(),
                    inventoryValidity: $('#inventoryValidity').val() || null
                };

                // 添加物料分类筛选
                if (currentMaterialTypeId) {
                    params.materialTypeId = currentMaterialTypeId;
                }

                return params;
            }

            // 搜索数据
            window.searchData = function () {
                var params = getSearchParams();
                var hasSearchCondition = Object.values(params).some(function(value) {
                    return value !== null && value !== '';
                });

                if (!hasSearchCondition) {
                    layer.msg('请输入搜索条件', { icon: 0 });
                    return;
                }

                layer.msg('正在搜索...', { icon: 16, time: 1000 });
                reloadTable();
            };

            // 重置搜索
            window.resetSearch = function () {
                $('#productMaterielCode').val('');
                $('#productMaterielName').val('');
                $('#warehouseName').val('');
                $('#supplierName').val('');
                $('#inventoryValidity').val('');
                currentMaterialTypeId = null;
                
                // 重置树选择
                tree.setChecked('materialTypeTreeId', 0);
                
                layer.msg('搜索条件已重置', { icon: 1, time: 1500 });
                reloadTable();
            };

            // 导出数据
            window.exportData = function () {
                var params = getSearchParams();
                layer.confirm('确定要导出当前查询结果吗？', {
                    icon: 3,
                    title: '导出确认'
                }, function(index) {
                    layer.close(index);
                    layer.msg('导出功能开发中...', { icon: 0 });
                    // TODO: 实现导出功能
                });
            };

            // 刷新数据
            window.refreshData = function () {
                layer.msg('正在刷新数据...', { icon: 16, time: 1000 });
                reloadTable();
            };

            // 查看详情
            window.viewDetail = function (id) {
                if (!id) {
                    layer.msg('无效的记录ID', { icon: 2 });
                    return;
                }

                var loadIndex = layer.load(2, { shade: [0.3, '#000'] });
                
                $.ajax({
                    url: '/WarehouseManagement/InventoryModel/Get',
                    method: 'GET',
                    data: { id: id },
                    success: function (res) {
                        layer.close(loadIndex);
                        if (res.code === 0 && res.data) {
                            showDetailDialog(res.data);
                        } else {
                            layer.msg('获取详情失败：' + (res.msg || '未知错误'), { icon: 2 });
                        }
                    },
                    error: function () {
                        layer.close(loadIndex);
                        layer.msg('获取详情失败，请检查网络连接', { icon: 2 });
                    }
                });
            };

            // 显示详情对话框
            function showDetailDialog(data) {
                var content = `
                    <div style="padding: 20px; line-height: 1.8;">
                        <div style="display: grid; grid-template-columns: 1fr 1fr; gap: 15px;">
                            <div><strong>物料编号：</strong>${data.productMaterielCode || '-'}</div>
                            <div><strong>物料名称：</strong>${data.productMaterielName || '-'}</div>
                            <div><strong>规格型号：</strong>${data.specifications || '-'}</div>
                            <div><strong>在库数量：</strong><span style="color: #1890ff; font-weight: bold;">${data.quantityInStock || 0} ${data.unit || ''}</span></div>
                            <div><strong>入库批次：</strong>${data.inboundBatchNumber || '-'}</div>
                            <div><strong>仓库位置：</strong>${data.warehouseName || '-'} - ${data.warehouseArea || '-'} - ${data.warehouseLocation || '-'}</div>
                            <div><strong>供应商编号：</strong>${data.supplierCode || '-'}</div>
                            <div><strong>供应商名称：</strong>${data.supplierName || '-'}</div>
                            <div><strong>供应商简称：</strong>${data.supplierAbbreviation || '-'}</div>
                            <div><strong>生产工单：</strong>${data.productionWorkOrder || '-'}</div>
                            <div><strong>入库日期：</strong>${data.inboundDate ? util.toDateString(data.inboundDate, 'yyyy-MM-dd') : '-'}</div>
                            <div><strong>库存状态：</strong>${data.inventoryValidity ? '<span style="color: #52c41a;">有效</span>' : '<span style="color: #ff4d4f;">无效</span>'}</div>
                        </div>
                    </div>
                `;

                layer.open({
                    type: 1,
                    title: '库存详情 - ' + (data.productMaterielName || '未知物料'),
                    skin: 'layui-layer-rim',
                    area: ['700px', 'auto'],
                    maxmin: true,
                    content: content
                });
            }

            // 重新加载表格
            function reloadTable() {
                if (tableIns) {
                    tableIns.reload({
                        where: getSearchParams(),
                        page: {
                            curr: 1
                        }
                    });
                }
            }

            // 监听键盘事件
            $(document).on('keypress', 'input', function(e) {
                if (e.which === 13) { // 回车键
                    searchData();
                }
            });
        });
    </script>
</body>
</html> 